import Vue from 'vue'
import VueRouter from 'vue-router'

// 解决ElementUI在导航栏中的vue-router在3.0以上版本中重复点击菜单出错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('components/login/login.vue'),
    meta: { title: '登录' }
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('components/home/home.vue'),
    meta: { title: '首页' },
    redirect: '/welcome',
    children: [
      {
        path: '/welcome',
        name: 'welcome',
        component: () => import('components/welcome/welcome.vue'),
        meta: { title: '欢迎' }
      },
      // 用户列表
      {
        path: '/users',
        name: 'users',
        component: () => import('views/user/user.vue'),
        meta: { title: '用户列表' }
      },
      // 角色列表
      {
        path: '/roles',
        name: 'roles',
        component: () => import('views/roles/roles.vue'),
        meta: { title: '角色列表' }
      },
      // 权限列表
      {
        path: '/rights',
        name: 'rights',
        component: () => import('views/rights/rights.vue'),
        meta: { title: '权限列表' }
      },
      // 商品分类
      {
        path: '/categories',
        name: 'categories',
        component: () => import('views/goods/cate.vue'),
        meta: { title: '商品分类' }
      },
      {
        path: '/params',
        name: 'params',
        component: () => import('views/goods/params.vue'),
        meta: { title: '分类参数' }
      },
      {
        path: '/goods',
        name: 'goods',
        component: () => import('views/goods/goods.vue'),
        meta: { title: '商品列表' }
      },
      {
        path: '/goods/add',
        name: 'addGoods',
        component: () => import('views/goods/addGoods.vue'),
        meta: { title: '添加商品' }
      },
      {
        path: '/reports',
        name: 'reports',
        component: () => import('views/reports/reports.vue'),
        meta: { title: '数据报表' }
      },
      {
        path: '/orders',
        name: 'orders',
        component: () => import('views/goods/orders.vue'),
        meta: { title: '订单列表' }
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
